package cn.swu.lzr.Safe;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.CircleCaptcha;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.OutputStream;

public class Code extends HttpServlet {
    public final static String Auth_Code = "AUTH_CODE";

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {

        CircleCaptcha captcha = CaptchaUtil.createCircleCaptcha(120,60,4,30);
        String code = captcha.getCode();
        request.getSession(true).setAttribute(Auth_Code,code);
        try (OutputStream outputStream = response.getOutputStream()){
            captcha.write(outputStream);
        }
    }
}
